//
//  ST_PEImagePickerHeaderView.swift
//  btvideo
//
//  Created by mac on 2020/1/13.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_PEImagePickerHeaderView: UIView {
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = Color.white
        
        self.addSubview(cancel_btn)
        self.addSubview(right_btn)
        self.addSubview(center_btn)
        
        cancel_btn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(20-(44-24)/2.0)
            make.height.width.equalTo(44)
            make.top.equalToSuperview().offset(10-(44-24)/2.0)
        }
        
        right_btn.snp.makeConstraints { (make) in
            make.height.equalTo(30)
            make.width.equalTo(75)
            make.right.equalToSuperview().offset(-15)
            make.centerY.equalTo(cancel_btn)
        }
        
        center_btn.snp.makeConstraints { (make) in
            make.centerY.equalTo(cancel_btn)
            make.centerX.equalToSuperview()
            make.width.equalTo(130)
            make.height.equalTo(32)
        }
        
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    override func layoutSubviews() {
//        super.layoutSubviews()
//
//        if self.bounds.width > 10{
//            self.roundCorners([UIRectCorner.topLeft,UIRectCorner.topRight], radius: 16)
//        }
//
//    }
    
    
//    MARK: - Properties
    var close_closure:(()->())?
    fileprivate lazy var cancel_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setImageForAllStates(ST_ImageUtils.imageName("首页_icon_关闭")!)
        control.addTarget(self, action: #selector(close_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
  
    
    fileprivate lazy var right_btn:UIButton = {
            
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates("下一步")
        control.setTitleColorForAllStates(UIColor.white)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: UIFont.Weight.semibold)
        control.backgroundColor = Color.init(hexString: "#FEC207")
        control.cornerRadius = 15
        control.add_touch_up(insideTarget: self, action: #selector(right_handle))
            return control
    }()
    
    
    fileprivate lazy var center_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.setTitleForAllStates("所有照片")
        control.backgroundColor = Color.init(hex: 0xF2F4F7)
        control.cornerRadius = 16
        control.setImageForAllStates(ST_ImageUtils.imageName("视频_icon_向下")!)
        control.setTitleColorForAllStates(UIColor.init(hex: 0x333333)!)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: UIFont.Weight.semibold)
        control.semanticContentAttribute = .forceRightToLeft
        control.addTarget(self, action: #selector(select_album_handle), for: UIControl.Event.touchUpInside)
        return control
    }()
    
//    MARK: - Public Method
    func update_album_name(name:String){
        
        self.center_btn.setTitleForAllStates(name)
        
    }
    
    func set_center_btn_state_normal(){
        
        self.center_btn.isSelected = false
        
    }
    
//    MARK: - Event
    @objc func close_handle(){
        
        close_closure?()
        self.parentViewController?.dismiss(animated: true, completion: nil)
        
    }
    
    
   
    
    var finished_closure:(()->())?
    
    @objc func right_handle(){
        
        finished_closure?()
        
    }
    
    
    var select_album_closure:(()->())?
    
    var cancel_select_album_closure:(()->())?
    
    
    @objc func select_album_handle(){
        
        
        center_btn.isSelected = !center_btn.isSelected
        
        
        if center_btn.isSelected{
            select_album_closure?()
        }else{
            cancel_select_album_closure?()
        }
        
    }
    
    
}
